package com.zrgk.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.zrgk.bean.MarketBean;
import com.zrgk.service.EmpService;
import com.zrgk.service.MarketService;
import com.zrgk.util.PageUtil;

/**
 * DPS
 * @author Administrator
 * 销售计划  控制层
 */
@Controller
@RequestMapping(value="market.do")
public class MarketController {
	
	@Autowired
	@Qualifier(value="marketService")
	public MarketService marketService;
	@Autowired
	@Qualifier(value="empService")
	public EmpService empService;
	
	/**
	 *  查看详情
	 * @param request
	 * @return
	 */
	@RequestMapping(params = "method=list")
	public String listMarket(HttpServletRequest request){
		/*String nowPage = request.getParameter("page");
		PageUtil page = new PageUtil();
		Map<String,String> map = new HashMap<String, String>();*/
		List<MarketBean> markets = marketService.listMarket();
		/*if(nowPage!=null&&nowPage!="")
		{
			page.setNowPage(Integer.parseInt(nowPage));
		}
		page.setSearchInfo(map);*/
		/*for(MarketBean market : markets){
			System.out.println(market.getEmpId().getName());
		}*/
		/*marketService.findMarketByPage(page);
		request.setAttribute("page", page);*/
		request.setAttribute("market", markets);
		return "html/resource/market/plan/list.jsp";
		
	}
	
	/**
	 * 根据ID查询
	 * @param id
	 * @param request
	 * @return jsp
	 */
	@RequestMapping(params ="method=findById")
	public String findById(@RequestParam Integer id,HttpServletRequest request){
		MarketBean market2 = marketService.findById(id);
		//System.out.println(market2.getEmpId().getName());
		request.setAttribute("market", market2);
		return "html/resource/market/plan/view.jsp";
	}
	
	@RequestMapping(params ="method=findById2")
	public String findById(HttpServletRequest request,Integer id){
		MarketBean market2 = marketService.findById(id);
		//System.out.println(market2.getEmpId().getName());
		request.setAttribute("market", market2);
		return "html/resource/market/plan/edit.jsp";
	}
	
	/**
	 * 添加信息
	 * @return
	 */
	@RequestMapping(params ="method=insert")
	public String insertMarket(HttpServletRequest request,MarketBean market){
		//MarketBean mar = new MarketBean();
		/*mar.setMarketNo("003");
		mar.setDelStatus(2);*/
		String content = request.getParameter("content");
		marketService.insertMarket(market);
		request.setAttribute("market", market);
		//return "redirect:/index.jsp";
		return "redirect:html/resource/market/plan/result.jsp";
	}
	
	/**
	 * 修改
	 * @return
	 */
	@RequestMapping(params ="method=update")
	public String updateMarket(HttpServletRequest request,@RequestParam Integer id){
		MarketBean market = new MarketBean();
		market.setMarketId(2);
		
		marketService.updateMarket(market);
		request.setAttribute("market", market);
		return "html/resource/market/plan/result2.jsp";
	}

	public MarketService getMarketService() {
		return marketService;
	}

	public void setMarketService(MarketService marketService) {
		this.marketService = marketService;
	}
	

	

}
